const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");

module.exports = {
	mode: "development",
	devtool: "cheap-module-eval-source-map",
	entry: {
		main: "./webpack04-server/src/index.js"
	},

	devServer: {
		contentBase: "./dist",
		open: true,
		port: 8000,
		hot: true,
		hotOnly: true
	},

	module: {
		rules: [
			{
				test: /\.js$/,
				exclude: /node_modules/,
				loader: "babel-loader"
			}
		]
	},
	plugins: [
		new CleanWebpackPlugin(),
		new HtmlWebpackPlugin({
			template: "webpack04-server/src/template.html"
		}),
		new webpack.HotModuleReplacementPlugin()
	],
	output: {
		filename: "[name].js",
		path: path.resolve(__dirname, "dist")
	}
};
